// discountList.js
const regeneratorRuntime = require('../../lib/runtime');
const wx = require('../../lib/wx');
const Api = require('../../utils/api.js');
const wxapp = require('../../lib/wxapp');
const Util = require('../../utils/util.js');

// 获取应用实例
const app = getApp();
Page({
  data: {
    discountList: [
      {
        imgUrl: '../../images/no_image.png',
        url: '../discountDetail/discountDetail',
        name: '标题',
        description: '简介',
      }
    ],
  },

  goToMenu: wxapp.handler(function* goToMenu(next, e){
    const url = e.currentTarget.dataset.url;
    wx.reLaunch({
      url,
    });

    yield next;
  }),

  goToDetail: wxapp.handler(function* goToDetail(next, e){
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
    });

    yield next;
  }),

  onShow: wxapp.handler(function* onShow(next) {

    yield next;
  }),

  onLoad: wxapp.handler(function* onLoad(next) {

    var getPromList = Api.getPromList();
    var that = this;

    // 首页banner
    wx.request({
      url: getPromList,
      header: {
        'content-type': 'application/json'
      },
      method: 'GET',
      complete: function (res) {
        that.setData({ discountList: res.data.data });
      }
    });


    yield next;
  }),

});
